package com.brkj.course;

import java.util.List;

import android.widget.LinearLayout;
import com.dgl.sdk.view.CircleImageView;
import net.tsz.afinal.FinalBitmap;
import android.content.Context;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.brkj.model.DS_Comment;
import com.brkj.model.DS_Course;
import com.brkj.main.R;
import com.brkj.util.BitmapUtil;
import com.brkj.util.ImgShow;
import com.brkj.util.MyApplication;

public class CommentAdapter extends BaseAdapter{
	private ListItemView listItemView;
	protected LayoutInflater listContainer; 
	private Context context;
	private List<DS_Comment> commentList;
	private FinalBitmap fb;
	private Bitmap failBitmap;
	public CommentAdapter(Context context, List<DS_Comment> commentList){
		this.context = context;
		this.commentList = commentList;
		
		listContainer = LayoutInflater.from(context);
		fb = FinalBitmap.create(context);
		
		failBitmap =
				BitmapFactory.decodeResource(MyApplication.getContext().getResources(), R.drawable.note_head_small);
	}
	
	private static class ListItemView{
		public CircleImageView UserHeadImg;
		public TextView Name;
		public TextView Content;
		public TextView Time;
		public View verLine;
	};
	
	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return commentList.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return 0;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// 自定义视图
		listItemView = new ListItemView();
		// 获取list_item布局文件的视图
		if (convertView == null) {
			convertView = listContainer.inflate(R.layout.comment_item, null);
			// 获取控件对象
			listItemView.UserHeadImg = (CircleImageView) convertView.findViewById(R.id.UserHeadImg);
			listItemView.Name = (TextView) convertView
					.findViewById(R.id.Name);
			listItemView.Content = (TextView) convertView
					.findViewById(R.id.Content);
			listItemView.Time = (TextView) convertView
					.findViewById(R.id.Time);
            listItemView.verLine = convertView
					.findViewById(R.id.verLine);

			// 设置控件集到convertView
			convertView.setTag(listItemView);
		} else {
			listItemView = (ListItemView) convertView.getTag();
		}
		String url  = commentList.get(position).getUserHeadImg().replace('\\', '/');
		
//		fb.display(listItemView.CourseImg, commentList.get(position).getCourseImg());
		ImgShow.display(listItemView.UserHeadImg, url, R.drawable.note_head_small);
		
//		ImageLoader.getInstance().displayImage(
//				"http://118.192.9.79:7002/KMELearning//WebFiles/cwFiles/52266A266-BBFF-4482-A6A7-02196AB18763k.jpg"
//				, listItemView.CourseImg);
		listItemView.Name.setText(commentList.get(position).getName());
		listItemView.Content.setText(commentList.get(position).getContent());
		listItemView.Time.setText(commentList.get(position).getTime());

//        ViewGroup.LayoutParams params = listItemView.verLine.getLayoutParams();
//
//        params.height = convertView.getMeasuredHeight();
//
//        listItemView.verLine.setLayoutParams(params);

		return convertView;
	}

}
